import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Date;

public class UdpServer {
    private static final int PORT = 12345;

    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(PORT);
        while (true) {
            DatagramPacket request = new DatagramPacket(new byte[1024], 1024);
            socket.receive(request);
            String reciiveData = new String(request.getData(), 0, request.getLength());
            System.out.println("Receive data : " + reciiveData);
            String daytime = new Date().toString();
            byte[] data = daytime.getBytes();
            DatagramPacket response = new DatagramPacket(data, data.length, request.getAddress(), request.getPort());
            socket.send(response);
            System.out.println("Send data: " + daytime + " to ip: " + request.getAddress());

        }
    }


}
